/* tracking of a simulated bug
 * for biomimetic modelling

 */


#include "globals.h"
#include "BugTrackApp.h"
#include "BugSimple.h"

using namespace std;

BugTrackApp* app;
int window1ID, window2ID;

void display(void) {
	app->DisplayCallback();
}

void reshape(int w, int h) {
	app->ResizeCallback(w,h);
}

void idle(void) {
	app->IdleCallback();
}

void mouse(int button, int state, int x, int y) {
	app->MouseCallback(button, state, x, y);
}

void keyboard(unsigned char key, int x, int y) {
	app->KeyboardCallback(key, x, y);
}

int main( int argc, char* argv[] )
{
	
	cout<<"Bugtracker... \n";
	cout<<"\n Your System Properties: \n";

	bool doTracking = (argc == 2); // don't do tracking just draw it and save images
	cout<<"input arg: "<<doTracking<<"<- "<<argc<<"\n";

	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB );
	int w = 200;
	int h = 200;
	// window 1
	glutInitWindowSize(2*w, 3*h); // MAIN WINDOW TOP DOWN VIEW
	glutInitWindowPosition(1,1);
	window1ID = glutCreateWindow("window one");
	glutDisplayFunc( display );
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutMouseFunc(mouse);

	// window2
	int mult_win = NUMCAMS;
	

	if( mult_win > 1 ) {
		glutInitWindowSize(2*w, 3*h);
		glutInitWindowPosition(300,1);
		window2ID = glutCreateWindow("window two");
		glutDisplayFunc( display );
		glutReshapeFunc(reshape);
		glutKeyboardFunc(keyboard);
		glutMouseFunc(mouse);
	}

	// window3
	if( mult_win > 2 ) {
		glutInitWindowSize(2*w, 3*h);
		glutInitWindowPosition(600,1);
		window2ID = glutCreateWindow("window three");
		glutDisplayFunc( display );
		glutReshapeFunc(reshape);
		glutKeyboardFunc(keyboard);
		glutMouseFunc(mouse);
	}
	// window4
	if( mult_win > 3) {
		glutInitWindowSize(2*w, 3*h);
		glutInitWindowPosition(3*w+10,1);
		window2ID = glutCreateWindow("window four");
		glutDisplayFunc( display );
		glutReshapeFunc(reshape);
		glutKeyboardFunc(keyboard);
		glutMouseFunc(mouse);
	}
	// window5
	if( mult_win > 4 ) {
		glutInitWindowSize(w,h);
		glutInitWindowPosition(3*w+10,h+60);
		window2ID = glutCreateWindow("window five");
		glutDisplayFunc( display );
		glutReshapeFunc(reshape);
		glutKeyboardFunc(keyboard);
		glutMouseFunc(mouse);
	}
	
	// the idle func is shared
	glutIdleFunc(idle);

	cout<<"OpenGL version: "<<glGetString( GL_VERSION )<<"\n";
	cout<<"Vendor: "<<glGetString( GL_VENDOR )<<"\n";
	cout<<"Renderer: "<<glGetString( GL_RENDERER )<<"\n";
	cout<<"done glutInit...\n";

	app = new BugTrackApp(w, h, mult_win);
	app->Tracking( doTracking );
	glutMainLoop();


	return 0;


}